<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8" />
    <!--如果是IE 就以标准渲染-->
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />

    <!-- 视窗——————响应式布局 -->
    <meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0" />

    <!--当前页面的三要素-->
    <title>运维系统</title>
    <meta name="description" content="聚能优电" />
    <meta http-equiv="keywords" content="聚能优电" />
    <script type="text/javascript" src="./js/verify.js"></script>
    <script type="text/javascript" src="./js/common/commonfuntion.js"></script>

    <script type="text/javascript" src="https://webapi.amap.com/maps?v=1.4.15&key=7a44cb76d3cf44a85fe8394f46048349&plugin=AMap.Geocoder"></script>
    <!-- css -->
    <!-- <link rel="stylesheet" type="text/css" href="./css/ywzt.css" /> -->
    <link rel="stylesheet" type="text/css" href="./css/common/common.css" />
    <link rel="stylesheet" type="text/css" href="./css/jquery-accordion-menu.css" />
    <link rel="stylesheet" type="text/css" href="./css/mainmonitor_sz.css" />
    <style>

        #ywnum  #ywnumwrap.ywnum{
            width:100%;
            font-size:0px;
        }
        #ywnum  #ywnumwrap.ywnum p{
            font-size: 12px;
            display:inline-block;
            width:50%;
        }
        #ywnum  #ywnumwrap.ywnum p span{
            display:inline-block;
            font-size: 12px;
            height:30px;
            line-height:30px;
            font-weight: bold;
            font-family: MicrosoftYaHei;
            color: #CDDDF3;
        }
        #ywnum  #ywnumwrap.ywnum p span:first-child{
            margin-left: 5px;
            width:35%;
        }

    </style>
    

</head>

<body>
    <div id="container" class="mainmonitor_sz">
        <div class="mainmonitor_sz_01">
            <!--主屏内容-->
            <div class="mainmonitor_sz_screen">
                <div class="m_title">
                    <a href="JavaScript:history.go(-1);" class="back">
                        <img src="./images/back.svg" alt="" />
                    </a>
                    <span class="tit" id="projectNameCN"></span>
                </div>

                <div class="m_content">
                    <header class="tabHead" id="tabHead">
                        <span class="active" style="width:25%"><i>项目状态</i></span>
                        <span style="width:25%"><i>数据报表</i></span>
                    </header>
                    <article class="khfxWarp khfxWarpaa" id="khfxWarp" style="background: #112957;box-shadow: 0 6px 12px 0 rgba(0,16,40,0.33);border-radius: 4px;">
                        <div class="khfxPane xmzt khfxPaneaa" id="firstkhfxPane">
                            <div class="zt1 ztdetail firstdetail" id="ywnum">

                                <div style="font-size: 0.20rem;color: #8a95a5;font-weight: bold;letter-spacing: 0.88px;padding-left:10px;">
                                    <div id="showadd" style="display:block;"></div>
                                    <div id="showtime"></div>
                                </div>

                                <div class="tit_tit" id="tit_tit">
                                    <img src="./images/titicon.svg" alt="" />
                                    <span>运维人员</span>
                                </div>
                                <div class="ywnum" id="ywnumwrap">
                                </div>
                            </div>


                            <div class="zt2 ztdetail firstdetail">
                                
                                <div class="tit_tit" id="tit_tit">
                                    <img src="./images/titicon.svg" alt="" />
                                    <span>数据总览</span>
                                </div>

                                <ul>
                                    <li>
                                        <p>负载功率</p>
                                        <div class="ztdiv">
                                            <span id="dbitap0"></span><span>kW</span>
                                        </div>
                                    </li>
                                    <li>
                                        <p>当日用电量</p>
                                        <div class="ztdiv">
                                            <span id="trrp0"></span><span>kWh</span>
                                        </div>
                                    </li>
                                    <li>
                                        <p>发电功率</p>
                                        <div class="ztdiv">
                                            <span id="cyjpowerGeneration0">0</span><span>kW</span>
                                        </div>
                                    </li>
                                </ul>

                                <ul>
                                    <li>
                                        <p>PCS功率</p>
                                        <div class="ztdiv">
                                            <span id="pcstap0"></span><span>kW</span>
                                        </div>
                                    </li>
                                    <li>
                                        <p>SOC</p>
                                        <div class="ztdiv">
                                            <span id="bmssoc0">0</span><span>%</span>
                                        </div>
                                    </li>
                                    <li>
                                        <p>SOH</p>
                                        <div class="ztdiv">
                                            <span id="bmssoh0"></span><span>%</span>
                                        </div>
                                    </li>
                                </ul>

                            </div>
                            <div id="cyjdiv">

                            

                                <!-- <div class="zt2 ztdetail" style="margin-top: 0.3rem;">
                                    <div class="tit_tit">
                                        <img src="./images/titicon.svg" alt="" />
                                        <span>柴油机</span>
                                    </div>
                                    <div>

                                    

                                        <ul>
                                            <li>
                                                <p>发电功率</p>
                                                <div class="ztdiv">
                                                    <span id="powerGeneration">0</span><span>kW</span>
                                                </div>
                                            </li>

                                            <li>
                                                <p>转速</p>
                                                <div class="ztdiv">
                                                    <span id="dPlus">0</span><span>L</span>
                                                </div>
                                            </li>
                                            
                                        </ul>
                                    </div>
                                </div> -->
                            </div>

                            <div class="zt2 ztdetail" style="margin-top: 0.3rem;">
                                <div class="tit_tit">
                                    <img src="./images/titicon.svg" alt="" />
                                    <span>电表</span>
                                </div>

                                <ul>
                                    <li>
                                        <p>总有功功率</p>
                                        <div class="ztdiv">
                                            <span id="itap">0</span><span>kW</span>
                                        </div>
                                    </li>
                                    <li>
                                        <p>正向有功总电量</p>
                                        <div class="ztdiv">
                                            <span id="tpap">0</span><span>kWh</span>
                                        </div>
                                    </li>
                                    
                                </ul>
                            </div>

                            <div class="zt2 ztdetail" style="margin-top: 0.3rem;">
                                <div class="tit_tit">
                                    <img src="./images/titicon.svg" alt="" />
                                    <span>储能变流器</span>
                                </div>

                                <ul>
                                    <li>
                                        <p>总有功功率</p>
                                        <div class="ztdiv">
                                            <span id="tap">0</span><span>kW</span>
                                        </div>
                                    </li>
                                    <li>
                                        <p>总视在功率</p>
                                        <div class="ztdiv">
                                            <span id="tApparentP">0</span><span>kVA</span>
                                        </div>
                                    </li>
                                    <li>
                                        <p>总无功功率</p>
                                        <div class="ztdiv">
                                            <span id="trp">0</span><span>kVar</span>
                                        </div>
                                    </li>
                                </ul>
                                
                            </div>

                            <div class="zt2 ztdetail" style="margin-top: 0.3rem;">
                                
                                <div class="tit_tit">
                                    <img src="./images/titicon.svg" alt="" />
                                    <span>储能电池</span>
                                </div>
                                
                                <ul>
                                    <li>
                                        <p>SOC</p>
                                        <div class="ztdiv">
                                            <span id="soc">0</span><span>%</span>
                                        </div>
                                    </li>
                                    <li>
                                        <p>总电压</p>
                                        <div class="ztdiv">
                                            <span id="group_V">0</span><span>V</span>
                                        </div>
                                    </li>
                                    <li>
                                        <p>总电流</p>
                                        <div class="ztdiv">
                                            <span id="group_I">0</span><span>A</span>
                                        </div>
                                    </li>
                                </ul>
                            </div>

                            <div class="zt2 ztdetail" style="margin-top: 0.3rem;">
                                <div class="tit_tit">
                                    <img src="./images/titicon.svg" alt="" />
                                    <span>温湿度</span>
                                </div>
                                
                                <ul>
                                    <li>
                                        <p>EMS温度</p>
                                        <div class="ztdiv">
                                            <span id="temperature">0</span><span>℃</span>
                                        </div>
                                    </li>
                                    <li>
                                        <p>环境温度</p>
                                        <div class="ztdiv">
                                            <span id="environmentalT">0</span><span>℃</span>
                                        </div>
                                    </li>
                                    <li>
                                        <p>模块温度</p>
                                        <div class="ztdiv">
                                            <span id="cabinetT">0</span><span>℃</span>
                                        </div>
                                    </li>
                                </ul>
                            </div>

                            <div class="zt2 ztdetail" style="margin-top: 0.3rem;">
                                
                                <div class="tit_tit">
                                    <img src="./images/titicon.svg" alt="" />
                                    <span>设备状态</span>
                                </div>
                                
                                <ul>
                                    <li>
                                        <p>交流调度</p>
                                        <div class="ztdiv jldt">
                                            <span class="onoff" id="jldd"></span>
                                        </div>
                                    </li>
                                    <li>
                                        <p>直流调度</p>
                                        <div class="ztdiv">
                                            <span class="onoff" id="zldd"></span>
                                        </div>
                                    </li>
                                    <li>
                                        <p>并网</p>
                                        <div class="ztdiv">
                                            <span class="onoff" id="bw"></span>
                                        </div>
                                    </li>
                                    <li>
                                        <p>离网</p>
                                        <div class="ztdiv">
                                            <span class="onoff" id="lw"></span>
                                        </div>
                                    </li>
                                </ul>

                                <ul>
                                    <li>
                                        <p>等待开机</p>
                                        <div class="ztdiv jldt">
                                            <span class="onoff" id="ddkj"></span>
                                        </div>
                                    </li>
                                    <li>
                                        <p>离网运行</p>
                                        <div class="ztdiv zldd">
                                            <span class="onoff" id="lwyx"></span>
                                        </div>
                                    </li>
                                    <li>
                                        <p>并网切离网</p>
                                        <div class="ztdiv pcstxzt">
                                            <span class="onoff" id="bwqlw"></span>
                                        </div>
                                    </li>
                                    <li>
                                        <p>并网运行</p>
                                        <div class="ztdiv bmstxzt">
                                            <span class="onoff" id="bwyx"></span>
                                        </div>
                                    </li>
                                </ul>

                            </div>


                        </div>

                        <div class="khfxPane xmzt khfxPaneaa" id="thirdkhfxPane" style="width: 90%;padding:0 5% 0.4rem;">
                            <div class="select_wrap">
                                <select id="selectsb" value=""></select>
                            </div>

                            <div class="tablist" id="tablist">
                                <div class="list listcon">
                                    <div class="nyztab">
                                        <span class="active">一周</span>
                                        <span>月份</span>
                                        <span>一年</span>
                                    </div>
                                    <div class="nyz">
                                        <span class="nyzcon theweek weekyear" id="theweek"></span>
                                        <span class="nyzcon themounth" id="themounth">
                                            <div class="selectmonth_wrap">
                                                <select id="selectmonth" value="">
                                                </select>
                                                <!-- <img src="./images/xiala.svg" alt=""> -->
                                            </div>
                                            <div class="mounth_wrap" id="thedetailmounth"></div>
                                        </span>
                                        <span class="nyzcon theyear weekyear" id="theyear"></span>
                                    </div>
                                </div>
                            </div>
                        </div>


                    </article>
                </div>
            </div>
        </div>
    </div>

    <script>
        (function (win, doc) {
            var docEl = doc.documentElement || document.body; //获取HTML标签

            var container = doc.getElementById("container"); //container元素
            //判断是移动端设备还是PC,移动 就采用'orientationchange',横竖屏事件，PC端就采用onresize，窗口改变时间
            var resize =
                "onorientationchange" in win ? "orientationchange" : "resize";

            function rem() {
                docEl.style.fontSize = 100 * (container.clientWidth / 750) + "px";
            }

            //监听'DOMContent事件:DOM加载完成执行,如果DOMContent事件，那么执行rem函数
            doc.addEventListener("DOMContentLoaded", rem, false);

            //win下监听resize事件,如果resize事件，那么执行rem函数
            win.addEventListener(resize, rem, false);
        })(window, document);
    </script>
    <!-- js -->
    <script type="text/javascript" src="./js/jquery-3.4.1.js"></script>
    <script type="text/javascript" src="js/echarts.js"></script>
    <script type="text/javascript" src="./layer/layer.js"></script>
    <script>
        $(document).ready(function () {
            // var index = layer.load(0, {
            //     shade: [0.8, '#fff']
            // }); //0.1透明度的白色背景
            var projectid = GetQueryString('projectid');
            // var projectid = 76;
            // var linechartid = GetQueryString('linechartid');
            var projectNameCN = GetQueryString('projectNameCN');
            var description = GetQueryString('description');
            
            $("#projectNameCN").html(' ');
            $("#projectNameCN").html(projectNameCN);

            $.ajax({
                type: "GET",
                dataType: "json",
                url: "http://112.74.169.99:21021/api/services/app/ProjectService/GetYWProjectMemberListByProjectId?id=" + projectid,
                beforeSend: function (xhr) {
                    xhr.setRequestHeader("Accept", "application/json, text/javascript, */*; q=0.01");
                    xhr.setRequestHeader("Authorization", accessToken);
                    xhr.setRequestHeader('.AspNetCore.Culture', 'zh-Hans');
                },
                success: function (res) {
                    // console.log(res);
                    $("#ywnumwrap").html(` `);
                    $("#ywnumwrap").html( showywnum(res.result) );
                },
                error: function (err) {
                    console.log("首次请求数据 请求失败");
                }
            });

            function showywnum(obj) {
                var str = '';
                if (obj.constructor==Array) {
                    if(obj.length == 0){
                        str += `<p style="font-weight: bold;font-family: MicrosoftYaHei;font-size: 14px;color: #CDDDF3;margin-left:18px;"><span>无</span></p>`
                    }else {
                        for(var i = 0, len = obj.length; i < len; i++){
                            str += `<p><span>` + obj[i].userName + `</span><span>` + obj[i].phoneNumber + `</span></p>`
                        }
                    }
                    return str
                }
                return obj;
            }

            
            $.ajax({
                type: "GET",
                dataType: "json",
                url: "http://112.74.169.99:21021/api/TokenAuth/GetProjectData?projectid=" + projectid,
                beforeSend: function (xhr) {
                    xhr.setRequestHeader("Accept", "application/json, text/javascript, */*; q=0.01" );
                    xhr.setRequestHeader("Authorization", accessToken);
                    xhr.setRequestHeader('.AspNetCore.Culture', 'zh-Hans');
                },
                success: function (res) {
                    var data = res.result;


                    // 获取经纬度地址
                    var longitude = res.result[0].longitude.toString();
                    var latitude = res.result[0].latitude.toString();
                    var newlong = ToDigital(longitude.substring(0,3), longitude.substring(3,5), longitude.substring(5,7));
                    var newlat = ToDigital(latitude.substring(0,2), latitude.substring(2,4), latitude.substring(4,6));


                    function ToDigital(strDu, strFen, strMiao) {
                        strDu = (typeof (strDu) == "undefined" || strDu == "") ? 0 : parseFloat(strDu);
                        strFen = (typeof (strFen) == "undefined" || strFen == "") ? 0 : parseFloat(strFen) / 60;
                        strMiao = (typeof (strMiao) == "undefined" || strMiao == "") ? 0 : parseFloat(strMiao) / 3600;
                        var digital = strDu + strFen + strMiao;
                        if (digital == 0) {
                            return "";
                        } else {
                            return digital;
                        }
                    }

                    var lnglat = [newlong/10,newlat];
                    // console.log(lnglat);
                    function convertFrom(lnglat, type){
                        AMap.convertFrom(lnglat, type, function (status, result) {
                            if (result.info === 'ok') {
                                var geocoder = new AMap.Geocoder();
                                var lnglats = [result.locations[0].lng, result.locations[0].lat]
                                geocoder.getAddress(lnglats, function(status, address) {
                                    if (status === 'complete' && address.info === 'OK') {
                                        // console.log(address.regeocode.formattedAddress);
                                        $("#showadd").html(address.regeocode.formattedAddress);
                                    }
                                })
                            }
                        });
                    }
                    convertFrom(lnglat,'gps');



                    if (data.length == 0) {
                        layer.open({
                            type: 1,
                            content: '<div>' + '通讯异常' +
                                '</div>',
                            btn: '确定',
                            btnAlign: 'c', //按钮居中
                            shade: 0, //不显示遮罩
                            yes: function () {
                                layer.closeAll();
                                // layer.close(index);
                            }
                        });
                    } else {
                        let time = data[0].creationTime.split('T');

                        $("#showtime").html(' ');
                        $("#showtime").html(description + ' 数据更新时间:' + time[1].substring(0,8));

                        // 十台柴油机
                        $("#cyjdiv").html('');
                        $("#cyjdiv").html( tencyj(data.slice(1,11)) );


                        // 数据总览
                        $("#dbitap0").html( dealnumber(data[14].loadTAP) ); // 负载功率(电表总有功功率)
                        $("#trrp0").html( dealnumber(data[13].trrp) ); // 当日用电量

                        var powerGenerationten = 0;
                        for(var i=0;i<data.slice(1,11).length;i++){
                            powerGenerationten += data.slice(1,11)[i].powerGeneration;
                        }

                        $("#cyjpowerGeneration0").html( dealnumber(powerGenerationten) ); // 发电功率(柴油机)

                        $("#pcstap0").html( dealnumber(data[11].tap) ); // PCS总有功功率(pcs)
                        
                        $("#bmssoc0").html( dealnumber(data[12].soc) ); // soc(bms)
                        $("#bmssoh0").html( dealnumber(data[12].soh) ); // soh(bms)



                        // 电表
                        $("#itap").html(data[13].itap);  //总有功功率
                        $("#tpap").html(data[13].tpap);  //正向有功总电量

                        // 储能变流器 PCS
                        $("#tap").html(data[11].tap); // PCS总有功功率
                        $("#tApparentP").html(data[11].tApparentP); // PCS总视在功率
                        $("#trp").html(data[11].trp); // PCS总无功功率

                        // 储能电池 BMS
                        $("#soc").html(data[12].soc); // SOC
                        $("#group_V").html(data[12].group_V); // 总电压
                        $("#group_I").html(data[12].group_I); // 总电流

                        // 温湿度
                        $("#temperature").html( dealnumber(data[0].temperature) ); //EMS温度
                        $("#environmentalT").html( dealnumber(data[11].environmentalT) ); //环境温度
                        $("#cabinetT").html( dealnumber(data[11].cabinetT) ); //模块温度

                        // 设备状态
                        if (data[11].acDispatch === 0) {
                            // 交流调度
                            $("#jldd").attr('class', 'onoff zton');
                            // 直流调度
                            $("#zldd").attr('class', 'onoff ztoff');
                        } else if(data[11].acDispatch === 1) {
                            // 交流调度
                            $("#jldd").attr('class', 'onoff ztoff');
                            // 直流调度
                            $("#zldd").attr('class', 'onoff zton');
                        }
                        if (data[11].gridState === 0) {
                            // 并网
                            $("#bw").attr('class', 'onoff zton');
                            // 离网
                            $("#lw").attr('class', 'onoff ztoff');
                        } else if(data[11].gridState === 1) {
                            // 并网
                            $("#bw").attr('class', 'onoff ztoff');
                            // 离网
                            $("#lw").attr('class', 'onoff zton');
                        }

                        // 等待开机 离网运行 并网切离网 并网运行
                        if (data[0].workMode === 1) {
                            $("#ddkj").attr('class', 'onoff zton');
                            $("#lwyx").attr('class', 'onoff ztoff');
                            $("#bwqlw").attr('class', 'onoff ztoff');
                            $("#bwyx").attr('class', 'onoff ztoff');
                        } else if(data[0].workMode === 2) {
                            $("#ddkj").attr('class', 'onoff ztoff');
                            $("#lwyx").attr('class', 'onoff zton');
                            $("#bwqlw").attr('class', 'onoff ztoff');
                            $("#bwyx").attr('class', 'onoff ztoff');
                        } else if(data[0].workMode === 3) {
                            $("#ddkj").attr('class', 'onoff ztoff');
                            $("#lwyx").attr('class', 'onoff ztoff');
                            $("#bwqlw").attr('class', 'onoff zton');
                            $("#bwyx").attr('class', 'onoff ztoff');
                        } else if(data[0].workMode === 4) {
                            $("#ddkj").attr('class', 'onoff ztoff');
                            $("#lwyx").attr('class', 'onoff ztoff');
                            $("#bwqlw").attr('class', 'onoff ztoff');
                            $("#bwyx").attr('class', 'onoff zton');
                        }

                        setInterval(updateData,3000);
                    }

                },
                error: function (err) {
                    console.log("首次请求数据 请求失败");
                }
            });
            


            $("#cyjclick").click(function(){
                window.location.href='./mainmonitor_cyj.html?projectid=' + projectid;
            });


            $("#pcsclick").click(function(){
                window.location.href='./mainmonitor_pcs.html?projectid=' + projectid;
            });

            $("#bmsclick").click(function(){
                window.location.href='./mainmonitor_bms.html?projectid=' + projectid;
            });




            // tab选项卡切换
            $(".tabHead span").on("click", function () {
                var $this = $(this);
                var itemIndex = $this.index();
                $(this).addClass("active").siblings(".tabHead span").removeClass("active");
                $(".khfxPane").eq(itemIndex).show().siblings(".khfxPane").hide();
            });

            // 请求数据报表数据
            $.ajax({
                type: "GET",
                dataType: "json",
                url: "http://112.74.169.99:21021/api/services/app/ReportService/GetReportDLTDGDataByDay?type=1&groupid=1&projectid=" + projectid,
                beforeSend: function (xhr) {
                    xhr.setRequestHeader("Accept", "application/json, text/javascript, */*; q=0.01");
                    xhr.setRequestHeader("Authorization", accessToken);
                    xhr.setRequestHeader('.AspNetCore.Culture', 'zh-Hans');
                },
                success: function (res) {
                    if(res.success == true){
                        let dataall = res.result;
                        
                        $.ajax({
                            type: "GET",
                            dataType: "json",
                            url: "http://112.74.169.99:21021/api/services/app/DeviceGroupService/GetDeviceGroupsByProjectID?id=" + projectid,
                            beforeSend: function (xhr) {
                                xhr.setRequestHeader("Accept", "application/json, text/javascript, */*; q=0.01");
                                xhr.setRequestHeader("Authorization", accessToken);
                                xhr.setRequestHeader('.AspNetCore.Culture', 'zh-Hans');
                            },
                            success: function (res) {
                                
                                if(res.success == true){
                                    let data = res.result;
                                    $("#selectsb").html( selectsbeach(data) );
                                    $("#theweek").html( selectsbeachcon(dataall) );
                                    
                                }
                            }
                        });
                    }
                }
            });
            
            // 设备下拉框切换
            $("#selectsb").change(function () {
                let choicesb = $("#selectsb option:selected").attr('value');
                $(".tablist .listcon").eq(choicesb).show().siblings(".tablist .listcon").hide();
                let thetype;
                if(choicesb == 0){thetype = 1;}
                else{thetype = 0;}

                var choicewmy = $(this).parent().next().find('.nyztab span');
                $(choicewmy).each(function(index,item){
                    if($(item).hasClass('active')){

                        if(index == 0){ //一周
                            $.ajax({
                                type: "GET",
                                dataType: "json",
                                url: "http://112.74.169.99:21021/api/services/app/ReportService/GetReportDLTDGDataByDay?type="+thetype+"&groupid="+choicesb+"&projectid=" + projectid,
                                beforeSend: function (xhr) {
                                    xhr.setRequestHeader("Accept", "application/json, text/javascript, */*; q=0.01");
                                    xhr.setRequestHeader("Authorization", accessToken);
                                    xhr.setRequestHeader('.AspNetCore.Culture', 'zh-Hans');
                                },
                                success: function (res) {
                                    if(res.success == true){
                                        $("#theweek").html('');
                                        $("#theweek").html( selectsbeachcon(res.result) );
                                    }
                                }
                            });

                        }else if(index == 1){//月份
                            var index2 = layer.load(0, {
                                shade: [0.8, '#fff']
                            }); //0.1透明度的白色背景
                            var mouthchose = Number($("#selectmonth option:selected").attr('value')) + 1;

                            $.ajax({
                                type: "GET",
                                dataType: "json",
                                url: "http://112.74.169.99:21021/api/services/app/ReportService/GetReportDLTDGDataByMonth?type="+thetype+"&groupid="+choicesb+"&projectid="+projectid+"&month="+ mouthchose,
                                beforeSend: function (xhr) {
                                    xhr.setRequestHeader("Accept", "application/json, text/javascript, */*; q=0.01");
                                    xhr.setRequestHeader("Authorization", accessToken);
                                    xhr.setRequestHeader('.AspNetCore.Culture', 'zh-Hans');
                                },
                                success: function (res) {
                                    if(res.success == true){
                                        let data = res.result;

                                        $("#thedetailmounth").html('');
                                        $("#thedetailmounth").html(selectsbeachcon(data));
                                        layer.close(index2);
                                        

                                    }
                                }
                            });

                        }
                    }

                })



            });



             // 周月年切换选项卡切换
             $(".tablist .listcon .nyztab >span").on("click", function () {
                var groupid = $(this).parents('#tablist').prev().find('select').val();
                let thetype;
                if(groupid == 0){
                    thetype = 1;
                }else{
                    thetype = 0;
                }
                var itemIndex = $(this).index();
                $(this).addClass("active").siblings(".tablist .listcon .nyztab >span").removeClass("active"); 
                let nyzcon = $(this).parent().next().find(".nyzcon");
                nyzcon.eq(itemIndex).show().siblings(nyzcon).hide();

                if(itemIndex == 1){// 月份选项卡的数据
                    let nowmonth = Mounthnow();
                    $.ajax({
                        type: "GET",
                        dataType: "json",
                        url: "http://112.74.169.99:21021/api/services/app/ReportService/GetReportDLTDGDataByMonth?type="+thetype+"&groupid="+groupid+"&projectid="+projectid+"&month="+ nowmonth,
                        beforeSend: function (xhr) {
                            xhr.setRequestHeader("Accept", "application/json, text/javascript, */*; q=0.01");
                            xhr.setRequestHeader("Authorization", accessToken);
                            xhr.setRequestHeader('.AspNetCore.Culture', 'zh-Hans');
                        },
                        success: function (res) {
                            if(res.success == true){
                                let data = res.result;
                                $("#thedetailmounth").html('');
                                $("#thedetailmounth").html(selectsbeachcon(data));
                                $("#selectmonth").html(selectmontheach(nowmonth));
                                
                            }
                        }
                    });

                }else if(itemIndex == 2){// 年选项卡的数据
                    console.log("年选项卡的数据");
                }

            });


            // 月份下拉框切换
            $("#selectmonth").change(function () {

                var index1 = layer.load(0, {
                    shade: [0.8, '#fff']
                }); //0.1透明度的白色背景

                var mouthchose = Number($("#selectmonth option:selected").attr('value')) + 1;
                var groupid = $(this).parents('#tablist').prev().find("select").val();
                let thetype;
                if(groupid == 0){thetype = 1;}
                else{thetype = 0;}

                $.ajax({
                    type: "GET",
                    dataType: "json",
                    url: "http://112.74.169.99:21021/api/services/app/ReportService/GetReportDLTDGDataByMonth?type="+thetype+"&groupid="+groupid+"&projectid="+projectid+"&month="+ mouthchose,
                    beforeSend: function (xhr) {
                        xhr.setRequestHeader("Accept", "application/json, text/javascript, */*; q=0.01");
                        xhr.setRequestHeader("Authorization", accessToken);
                        xhr.setRequestHeader('.AspNetCore.Culture', 'zh-Hans');
                    },
                    success: function (res) {
                        if(res.success == true){
                            let data = res.result;
                            $("#thedetailmounth").html('');
                            $("#thedetailmounth").html(selectsbeachcon(data));
                            layer.close(index1);
                        }
                    }
                });
                
            });

            let num_index = 0;

            let load01 = 0,load02 = 0;
            let yj_left1=0,yj_left2=0;
            let pcs1_rp0=0,pcs2_rp0=0;

            function updateData() { // 请求数据
                num_index++;
                var onoff = isPositiveNum(num_index / 15); //一分钟增加一次数据

                $.ajax({
                    type: "GET",
                    dataType: "json",
                    url: "http://112.74.169.99:21021/api/TokenAuth/GetProjectData?projectid=" + projectid,
                    beforeSend: function (xhr) {
                        xhr.setRequestHeader("Accept", "application/json, text/javascript, */*; q=0.01");
                        xhr.setRequestHeader("Authorization", accessToken);
                        xhr.setRequestHeader('.AspNetCore.Culture', 'zh-Hans');
                    },
                    success: function (res) {
                        var data = res.result;
                        let time = data[0].creationTime.split('T');

                        $("#showtime").html(' ');
                        $("#showtime").html(description + ' 数据更新时间:' + time[1].substring(0,8));

                        // 十台柴油机
                        $("#cyjdiv").html('');
                        $("#cyjdiv").html( tencyj(data.slice(1,11)) );

                        // 数据总览
                        $("#dbitap0").html( dealnumber(data[14].loadTAP) ); // 负载功率(电表总有功功率)
                        $("#trrp0").html( dealnumber(data[13].trrp) ); // 当日用电量

                        var powerGenerationten = 0;
                        for(var i=0;i<data.slice(1,11).length;i++){
                            powerGenerationten += data.slice(1,11)[i].powerGeneration;
                        }

                        $("#cyjpowerGeneration0").html( dealnumber(powerGenerationten) ); // 发电功率(柴油机)
                        $("#pcstap0").html( dealnumber(data[11].tap) ); // PCS总有功功率(pcs)
                        
                        $("#bmssoc0").html( dealnumber(data[12].soc) ); // soc(bms)
                        $("#bmssoh0").html( dealnumber(data[12].soh) ); // soh(bms)

                        // 电表
                        $("#itap").html(data[13].itap);  //总有功功率
                        $("#tpap").html(data[13].tpap);  //正向有功总电量

                        // 储能变流器 PCS
                        $("#tap").html(data[11].tap); // PCS总有功功率
                        $("#tApparentP").html(data[11].tApparentP); // PCS总视在功率
                        $("#trp").html(data[11].trp); // PCS总无功功率

                        // 储能电池 BMS
                        $("#soc").html(data[12].soc); // SOC
                        $("#group_V").html(data[12].group_V); // 总电压
                        $("#group_I").html(data[12].group_I); // 总电流

                        // 温湿度
                        $("#temperature").html( dealnumber(data[0].temperature) ); //EMS温度
                        $("#environmentalT").html( dealnumber(data[11].environmentalT) ); //环境温度
                        $("#cabinetT").html( dealnumber(data[11].cabinetT) ); //模块温度

                        // 设备状态
                        if (data[11].acDispatch === 0) {
                            // 交流调度
                            $("#jldd").attr('class', 'onoff zton');
                            // 直流调度
                            $("#zldd").attr('class', 'onoff ztoff');
                        } else if(data[11].acDispatch === 1) {
                            // 交流调度
                            $("#jldd").attr('class', 'onoff ztoff');
                            // 直流调度
                            $("#zldd").attr('class', 'onoff zton');
                        }
                        if (data[11].gridState === 0) {
                            // 并网
                            $("#bw").attr('class', 'onoff zton');
                            // 离网
                            $("#lw").attr('class', 'onoff ztoff');
                        } else if(data[11].gridState === 1) {
                            // 并网
                            $("#bw").attr('class', 'onoff ztoff');
                            // 离网
                            $("#lw").attr('class', 'onoff zton');
                        }

                        // 等待开机 离网运行 并网切离网 并网运行
                        if (data[0].workMode === 1) {
                            $("#ddkj").attr('class', 'onoff zton');
                            $("#lwyx").attr('class', 'onoff ztoff');
                            $("#bwqlw").attr('class', 'onoff ztoff');
                            $("#bwyx").attr('class', 'onoff ztoff');
                        } else if(data[0].workMode === 2) {
                            $("#ddkj").attr('class', 'onoff ztoff');
                            $("#lwyx").attr('class', 'onoff zton');
                            $("#bwqlw").attr('class', 'onoff ztoff');
                            $("#bwyx").attr('class', 'onoff ztoff');
                        } else if(data[0].workMode === 3) {
                            $("#ddkj").attr('class', 'onoff ztoff');
                            $("#lwyx").attr('class', 'onoff ztoff');
                            $("#bwqlw").attr('class', 'onoff zton');
                            $("#bwyx").attr('class', 'onoff ztoff');
                        } else if(data[0].workMode === 4) {
                            $("#ddkj").attr('class', 'onoff ztoff');
                            $("#lwyx").attr('class', 'onoff ztoff');
                            $("#bwqlw").attr('class', 'onoff ztoff');
                            $("#bwyx").attr('class', 'onoff zton');
                        }

                    },
                    error: function (err) {
                        console.log("数据请求失败");
                    }
                });
            }

            function selectsbeach(obj) {
                var str = '';

                if (obj.constructor==Array) {
                    str += `<option value="0" >所有设备</option>`;
                    for(var i = 0, len = obj.length; i < len; i++){
                        str += `<option value="`+obj[i].id+`">`+obj[i].groupName+`</option>`
                    }
                    return str;
                }
                return obj;
            }

            function selectmontheach(nowmonth) {
                var str = '';

                for(var i = 0, len = nowmonth; i < len; i++){
                    let showmonth;
                    if(i==0){showmonth="一月"}
                    else if(i==1){showmonth="二月"}
                    else if(i==2){showmonth="三月"}
                    else if(i==3){showmonth="四月"}
                    else if(i==4){showmonth="五月"}
                    else if(i==5){showmonth="六月"}
                    else if(i==6){showmonth="七月"}
                    else if(i==7){showmonth="八月"}
                    else if(i==8){showmonth="九月"}
                    else if(i==9){showmonth="十月"}
                    else if(i==10){showmonth="十一月"}
                    else if(i==11){showmonth="十二月"}

                        
                    if( i!=(nowmonth-1) ){
                        str += `<option value="` + i + `">` + showmonth + `</option>`;
                        
                    }else if(i==(nowmonth-1)){
                        str += `<option value="` + i + `" selected>` + showmonth + `</option>`;
                    }
                }
                return str;

            }

            function selectsbeachcon(data) {
                var str = ``;
                for(var i=0;i<data.length;i++){
                    str += `
                    <div class="conlist">
                        <div class="listup">
                            <span></span><span>`+Mounthdate(data[i].time)+`</span>
                        </div>
                        <div class="listdown">
                            <ul>
                                <li>
                                    <p>燃油消耗</p>
                                    <div class="ztdiv">
                                        <span>`+data[i].usedAcc+`</span><span>L</span>
                                    </div>
                                </li>
                                <li>
                                    <p>发电量</p>
                                    <div class="ztdiv">
                                        <span>`+data[i].positiveKWh+`</span><span>kWh</span>
                                    </div>
                                </li>
                                <li>
                                    <p>用电量</p>
                                    <div class="ztdiv">
                                        <span>`+data[i].tpap+`</span><span>kWh</span>
                                    </div>
                                </li>
                            </ul>
                            <ul>
                                <li>
                                    <p>系统效率</p>
                                    <div class="ztdiv">
                                        <span>`+data[i].systemEfficiency+`</span><span></span>
                                    </div>
                                </li>
                                <li>
                                    <p>单位油耗</p>
                                    <div class="ztdiv">
                                        <span>`+data[i].unitConsumption+`</span><span></span>
                                    </div>
                                </li>
                                <li>
                                    <p>停电次数</p>
                                    <div class="ztdiv">
                                        <span>`+data[i].projectPowerFailure+`</span><span></span>
                                    </div>
                                </li>
                            </ul>
                        </div>
                    </div>`;
                } //for循环结束
                return str;
            }// 函数结束

            // 十台柴油机
            function tencyj(obj) {
                var str = '';
                if (obj.constructor==Array) {
                    // 柴油机
                    for (var i = 0, len = obj.length; i < len; i++) {

                    str +=  `<div class="zt2 ztdetail" style="margin-top: 0.3rem;">`;
                        if(i==0){
                        str +=  `<div class="tit_tit">
                                    <img src="./images/titicon.svg" alt="" />
                                    <span>柴油机</span>
                                </div>`;
                        };
                        str +=  `<div class="detail_tit">`;
                            if(i<9){
                                str += `<span>0`+(i+1)+`</span>`;
                            }else if(i>=9){
                                str += `<span>`+(i+1)+`</span>`;
                            }
                        str +=  `</div>`;
                        str +=  ` <ul>
                                    <li>
                                        <p>发电功率</p>
                                        <div class="ztdiv">
                                            <span id="powerGeneration`+i+`">` + obj[i].powerGeneration + `</span><span>kW</span>
                                        </div>
                                    </li>
                                    <li>
                                        <p>转速</p>
                                        <div class="ztdiv">
                                            <span id="rpm`+i+`">` + obj[i].rpm + `</span><span>r/min</span>
                                        </div>
                                    </li>
                                </ul>
                            </div>`;
                    }
                }
                return str;
            }

            // 判断是否为数字
            function isNumber(val) {
                if (val == "" || isNaN(val)) {
                    return false;
                } else {
                    return true;
                }
            }

            function numToText(obj){
                if(obj == 0){
                    obj = 无效;
                }else if(obj == 1){
                    obj = 有效;
                }
                return obj;
            }
            
        });
    </script>
</body>

</html>